package com.xuetang9.t9.hotel.services.impl;

import com.xuetang9.t9.hotel.beans.CommodityExpense;
import com.xuetang9.t9.hotel.beans.CommodityType;
import com.xuetang9.t9.hotel.mapper.ICommodityInfoMapper;
import com.xuetang9.t9.hotel.mapper.ICommodityTypeMapper;
import com.xuetang9.t9.hotel.mapper.condition.ICondition;
import com.xuetang9.t9.hotel.mapper.condition.impl.CommodityTypeCondition;
import com.xuetang9.t9.hotel.services.ICommodityExpenseService;
import com.xuetang9.t9.hotel.services.ICommodityTypeService;
import com.xuetang9.t9.hotel.utils.PageBean;
import com.xuetang9.t9.hotel.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommodityTypeServiceImpl implements ICommodityTypeService {

    @Autowired
    private ICommodityTypeMapper commodityTypeMapper;

    @Autowired
    private ICommodityInfoMapper commodityInfoMapper;


    @Override
    public boolean save(CommodityType commodityType) {
        if(commodityType == null){
            return false;
        }
        return commodityTypeMapper.insert(commodityType) > 0;
    }

    @Override
    public boolean update(CommodityType commodityType) {
        if(commodityType == null){
            return false;
        }
        return commodityTypeMapper.update(commodityType) > 0;
    }

    @Override
    public boolean remove(Integer id) {
        if(null == id){
            return false;
        }
        commodityInfoMapper.deleteByTypeId(id);
        return commodityTypeMapper.delete(id) > 0;
    }

    @Override
    public PageBean queryByAll(CommodityTypeCondition condition) {
        if(condition == null){
            condition = new CommodityTypeCondition();
        }
        List<CommodityType> commodityTypes = commodityTypeMapper.selectByAll(condition);
        PageBean pageBean = new PageBean();
        pageBean.ok(commodityTypes);
        pageBean.setCount(queryByCount(condition));
        return pageBean;
    }

    @Override
    public Long queryByCount(CommodityTypeCondition condition) {
        return commodityTypeMapper.selectByCount(condition);
    }
}
